package com.tul.exercise.base.jmockit.base;

import mockit.Expectations;
import org.junit.jupiter.api.Test;

import java.util.Locale;

import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * 《JMockit中文网》的最简单示例
 * HelloJMockit测试类
 */
public class HelloJMockitTest {
    /**
     * 测试场景：当前是在中国
     */
    @Test
    public void testSayHelloAtChina() {
        // 假设当前位置是在中国
        new Expectations(Locale.class) {
            {
                Locale.getDefault();
                result = Locale.CHINA;
            }
        };
        // 断言说中文
        HelloJMockit helloJMockit = new HelloJMockit();
        assertTrue("你好，JMockit!".equals((helloJMockit.sayHello())));
        System.out.println(helloJMockit.sayHello());
    }

    /**
     * 测试场景：当前是在美国
     */
    @Test
    public void testSayHelloAtUS() {
        // 假设当前位置是在美国
        new Expectations(Locale.class) {
            {
                Locale.getDefault();
                result = Locale.US;
            }
        };
        // 断言说英文
        HelloJMockit helloJMockit = new HelloJMockit();
        assertTrue("Hello，JMockit!".equals((helloJMockit.sayHello())));
        System.out.println(helloJMockit.sayHello());
    }
}
